<?php
/**
 * 模板消息
 * Created by PhpStorm.
 * User: qinzhi
 * Date: 2017/7/12
 * Time: 9:43
 */
class Service_Template{

    /**
     * 发送新订单提醒
     * @param $order_no
     */
    public static function set_tpl_msg($order_no){
        global $_F;
        require_once(APP_ROOT . 'lib/weixin/WeixinChat.class.php');
        $options = array(
            'token' => FConfig::get('wechat.seller.token'),
            'appid' => FConfig::get('wechat.seller.appid'),
            'appsecret' => FConfig::get('wechat.seller.appsecret'),
        );
        $weixin = new WeixinChat($options);
        $ordersT = new FTable('orders','','xhs_slave');
        $orders = $ordersT->where(array('o_id'=>$order_no))->find();
        $data = array(
            'first' => array('value'=> '收到一个新的订单'),
            'Day' => array('value'=> date('Y-m-d')),
            'orderId' => array('value'=> $order_no),
            'orderType' => array('value'=> '普通订单'),
            'customerName' => array('value'=> $orders['contact']),
            'customerPhone' => array('value'=> $orders['phone']),
            'remark' => array('value'=> '请及时处理您的订单。')
        );
        $clerkList = Service_Clerk::getClerkList($orders['shop_id']);
        foreach ($clerkList as $clerk){
            if(empty($clerk['openid'])) continue;
            $msgData = array(
                'touser' => $clerk['openid'],
                'template_id' => FConfig::get('templet.new_order_notice'),
                'url' => FConfig::get('global.burl') . '/order/manager?from=' . 'msg',
                'data' => $data
            );
            $weixin->sendTemplateMessage($msgData);
        }
    }
}